//
//  LLTVideoPlayerVC.swift
//  TakePhoto
//
//  Created by 李陆涛 on 2018/7/27.
//  Copyright © 2018年 llt. All rights reserved.
//

import UIKit

class LLTVideoPlayerVC: BaseVC {
    
    var videoURL:URL?
    var player:Player = Player()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
    }
    
    deinit {
        
        self.player.willMove(toParentViewController: nil)
        self.player.view.removeFromSuperview()
        self.player.removeFromParentViewController()
    }
    
    private func setupUI() {
        
        self.player.playerView.playerBackgroundColor = .black
        
        self.addChildViewController(self.player)
        self.view.addSubview(self.player.view)
        self.player.didMove(toParentViewController: self)
        
        self.player.url = videoURL
        self.player.playbackLoops = true
        

        let singleGesture = UITapGestureRecognizer(target: self, action: #selector(singleAction))
        singleGesture.numberOfTapsRequired = 1
        
        self.view.addGestureRecognizer(singleGesture)
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        self.player.playFromBeginning()
    }
    
    
    
    @objc func singleAction() {
        
        self.player.stop()
        
        self.dismiss(animated: true, completion: nil)
    }
}
